let audio = null;
let currentSource = null;
let currentTime = 0;
const AudioId = "#audio";

export function playMusic(source) {
  if (!audio) {
    audio = document.createElement("audio");
    audio.id = AudioId;
    audio.controls = false;
    audio.autoplay = false;
    currentTime = 0;
    document.body.append(audio);
  }
  if (!currentSource || currentSource !== source) {
    audio.src = source;
    currentTime = 0;
  }
  audio.currentTime = currentTime;
  currentSource = source;
  audio.play();
}

export function pauseMusic() {
  currentTime = audio.currentTime;
  audio.pause();
}
